module.exports = (proxyServer) => {
  return {
    '/seeyon': {
      target: proxyServer,
      changeOrigin: true,
      pathRewrite: { '^/seeyon': '/seeyon' },
      onProxyReq(req) {
        const url = new URL(proxyServer);
        req.setHeader('Host', url.host);
        req.setHeader('Origin', url.host);
        req.setHeader('Referer', proxyServer);
        // 防止nginx反向代理验证ip
        req.removeHeader('x-forwarded-for');
        req.removeHeader('x-forwarded-port');
        req.removeHeader('x-forwarded-host');
      },
      onProxyRes(res, rawRes) {
        const { statusCode, headers } = res;
        const { location } = headers;
        if (/^30[12]$/.test(String(statusCode)) && /:\/\//.test(location)) {
          const url = new URL(location);
          url.host = rawRes.headers.host;
          headers.location = url.href;
        }
      }
    },
    '/static': {
      changeOrigin: false,
      target: proxyServer
    },
    '/sportal': {
      target: proxyServer,
      changeOrigin: false,
      pathRewrite: {
        '^/sportal': '/sportal'
      }
    }
  };
};
